package cn.maszy.action.contract;



import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;

import net.sourceforge.stripes.action.SessionScope;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.model.contract.B_T_Ufp_Contract;
import cn.maszy.model.contract.B_T_Ufp_Payment;
import cn.maszy.service.contract.B_T_Ufp_ContractService;
import cn.maszy.service.contract.B_T_Ufp_PaymentService;


@SessionScope
public class ContractActiom extends BaseAction<B_T_Ufp_Contract> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2475349243064011153L;
	private B_T_Ufp_Contract b_T_Ufp_Contract;
	private B_T_Ufp_Payment b_T_Ufp_Payment;
	private Pager<B_T_Ufp_Payment> pagers;
	private String flag;
	@Autowired
	private B_T_Ufp_ContractService b_T_Ufp_ContractService;
	@Autowired
	private B_T_Ufp_PaymentService b_T_Ufp_PaymentService;
	private String checkIds;
	
	/*********************class set/get****************************/
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public B_T_Ufp_Contract getB_T_Ufp_Contract() {
		return b_T_Ufp_Contract;
	}
	public void setB_T_Ufp_Contract(B_T_Ufp_Contract b_T_Ufp_Contract) {
		this.b_T_Ufp_Contract = b_T_Ufp_Contract;
	}
	
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public B_T_Ufp_Payment getB_T_Ufp_Payment() {
		return b_T_Ufp_Payment;
	}
	public void setB_T_Ufp_Payment(B_T_Ufp_Payment b_T_Ufp_Payment) {
		this.b_T_Ufp_Payment = b_T_Ufp_Payment;
	}
	public Pager<B_T_Ufp_Payment> getPagers() {
		return pagers;
	}
	public void setPagers(Pager<B_T_Ufp_Payment> pagers) {
		this.pagers = pagers;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 页面查询
	 * @return
	 * @throws Exception
	 */
	public String contractList() throws Exception {
		pager = new Pager<B_T_Ufp_Contract>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_ContractService.selectList(b_T_Ufp_Contract,pager);	
		return SUCCESS;
	}
	
	/**
	 * 新增更新
	 * @return
	 * @throws Exception
	 */
	public String contractUpdate() throws Exception {
		int i	=b_T_Ufp_ContractService.update(b_T_Ufp_Contract,b_T_Ufp_Payment,flag);
		if(i>0)
			//目前只有点击提交后关闭
			//return ajaxForwardSuccess(getText("msg.operation.success"), "adminList", "closeCurrent", "investment/adminList");
		//保存不关闭暂时没做
		return ajaxForwardSuccess(getText("msg.operation.success"), "ContractList","", "forward", "contract/ContractList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 页面跳转
	 * @return
	 * @throws Exception
	 */
	public String contractJump() throws Exception {
		return SUCCESS;
	}
	/**
	 * 删除一条数据
	 * @return
	 * @throws Exception
	 */
	public String contractDel() throws Exception {
		int i=b_T_Ufp_ContractService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "ContractList","", "forward", "contract/ContractList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 查询一条数据
	 * @return
	 * @throws Exception
	 */
	public String contractDetail() throws Exception {
		if(b_T_Ufp_Contract==null){
			b_T_Ufp_Contract=b_T_Ufp_ContractService.selectOne("");
			String i = UUID.randomUUID().toString();
			b_T_Ufp_Contract.setUuid(i);
			
		}else{
			b_T_Ufp_Contract=b_T_Ufp_ContractService.selectOne(b_T_Ufp_Contract.getUuid());
			pagers = new Pager<B_T_Ufp_Payment>(pageNum, numPerPage,orderField,orderDirection);
			pagers = b_T_Ufp_PaymentService.selectList(b_T_Ufp_Payment, pagers, b_T_Ufp_Contract.getUuid());
		}
		return SUCCESS;
	}
}
